import { createStore } from 'vuex'

const MEMBER="MEMBER";

export default createStore({
  state: {
    /*优先从缓存中取,没有就用空对象*/
    /*注意,用window默认的全局变量去获取SessionStorage*/
    member: window.SessionStorage.get(MEMBER) || {}/*全局变量*/
  },
  getters: {
  },
  mutations: {
    setMember(state, _member) {
      state.member = _member; /*相当于set方法*/
      /*将member对象存储到缓存中*/
      window.SessionStorage.set(MEMBER, _member);
      console.log('Stored value:', window.SessionStorage.get(MEMBER));
    }
  },
  actions: {
  },
  modules: {
  }
})
